package com.leetcode.string.demo7;

/**
 * @Author Zan
 * @Create 2024/6/3 16:31
 * @ClassName: Test
 * @Description : https://leetcode.cn/problems/repeated-substring-pattern/  重复的子字符串
 */
public class Test {
    public static void main(String[] args) {
        String s = "abab";
        Solution solution = new Solution();
        boolean b = solution.repeatedSubstringPattern(s);
        System.out.println(b);
    }
}

class Solution {
    public boolean repeatedSubstringPattern(String s) {
        // 先找出最大的数
        int number = s.length() / 2 + 1;
        int start = 0;
        int end = 1;
        while (end < number) {
            int tempStart = start;
            int tempEnd = end;
            String tempStr = s.substring(start, end);
            int successNum = 1;
            while (tempEnd < number) {
                if ((s.substring(tempStart, tempEnd).equals(tempStr))) {
                    successNum++;
                }
                tempStart++;
                tempEnd++;
            }
            if ((s.length() / (end - start)) == successNum) {
                return true;
            }
            start++;
            end++;
        }
        return false;
    }
}
